<template>
  <div>
    <van-cell-group>
      <van-field
        v-model="user.phone"
        type="tel"
        label="手机号"
        placeholder="请输入手机号"
      />
      <van-field
        v-model="user.password"
        type="password"
        label="密码"
        placeholder="请输入密码"
      />
    </van-cell-group>
    <!-- <div class="input"> -->
    <!-- 
      <div>手机号： <input type="text" v-model="user.phone" /></div>
      <div>密码 ：<input type="text" v-model="user.password" /></div>  -->
    <!-- <button @click="login">点击登录</button> -->
    <van-button
      style="margin-top: 30px"
      class="input"
      round
      type="info"
      size="normal"
      color="pink"
      @click="login"
      >点击登录</van-button
    >
    <van-button
      style="margin-top: 30px"
      class="input"
      round
      type="info"
      size="normal"
      color="pink"
      @click="$router.push('/register')"
      > 前往注册</van-button
    >
    <!-- </div> -->
    <!-- 路由导航 -->
    <!-- <router-link to="/index">前往首页</router-link>
    -->
  </div>
</template>
<script>
import { relogin } from "../../http/http";
import { Toast } from "vant";
export default {
  data() {
    return {
      user: {
        phone: "",

        password: "",
      },
    };
  },
  methods: {
    login() {
      // 发请求
      relogin(this.user).then((res) => {
        console.log(res);
        if (res.data.code === 200) {
          // toast青提示· vant ui
          Toast({
            message: res.data.msg,
            position: "top",
          });

          //存用户的信息
          localStorage.setItem("userInfo", JSON.stringify(res.data.list));
          //   存放用户表示
          localStorage.setItem("islogin", 1);
          //   实现跳转
          this.$router.push("/index/store");
        } else {
          Toast({
            message: res.data.msg,
            position: "top",
          });
        }
      });
    },
  },
};
</script>
<<style scoped>
.input {
  width: 100%;
  
  text-align: center;

}
input {
  margin: 10px auto;
  
}

</style>